Passed
Push — task/word-counter-long-form-qu... ( 8bcc52 )
by Yonathan
09:25 queued 03:14
created

ProgressRing   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 2
1
import React from "react";
2
3
interface ProgressRingProps {
4
  radius: number;
5
  stroke: number;
6
  progress: number;
7
  strokeColor: string;
8
  max: number;
9
}
10
11
interface ProgressRingState {
12
  normalizedRadius: number;
13
  circumference: number;
14
}
15
16
const ProgressRing: React.FunctionComponent<ProgressRingProps> = ({
17
  radius,
18
  stroke,
19
  progress,
20
  strokeColor,
21
  max,
22
}) => {
23
  const normalizedRadius: number = radius - stroke * 2;
24
  const circumference: number = (radius - stroke * 2) * (2 * Math.PI);
25
  let strokeDashoffset: number =
26
    circumference - (progress / max) * circumference;
27
  if (strokeDashoffset < 0) {
28
    strokeDashoffset = 0;
29
  }
30
  return (
31
    <svg height={radius * 2} width={radius * 2}>
32
      <circle
33
        stroke="lightgrey"
34
        fill="transparent"
35
        strokeWidth={1}
36
        strokeDasharray={`${circumference} ${circumference}`}
37
        style={{ strokeDashoffset: 0 }}
38
        r={normalizedRadius}
39
        cx={radius}
40
        cy={radius}
41
      />
42
      <circle
43
        stroke={strokeColor}
44
        fill="transparent"
45
        strokeWidth={stroke}
46
        strokeDasharray={`${circumference} ${circumference}`}
47
        style={{ strokeDashoffset }}
48
        r={normalizedRadius}
49
        cx={radius}
50
        cy={radius}
51
      />
52
    </svg>
53
  );
54
};
55
56
export default ProgressRing;
57